package odgs.app.notuse;

import javax.swing.SwingUtilities;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;

public class ExplorerTreeController implements TreeSelectionListener 
{
	private ExplorerTreeUI ui;
	private ExplorerTreeModel model;
	
	public ExplorerTreeController(ExplorerTreeUI ui)
	{
		this.ui = ui;
	}
	
	public void setModel(ExplorerTreeModel model)
	{
		this.model = model;
		ui.explorerTree.setModel(model);
		ui.explorerTree.addTreeSelectionListener(this);
	}

	public void valueChanged(final TreeSelectionEvent e)
	{
		System.out.println(e.getPath());
		SwingUtilities.invokeLater(new Runnable(){
			public void run()
			{
				if (ui.explorerTree.isExpanded(e.getPath())){
					ui.explorerTree.collapsePath(e.getPath());
				}
				else
				{
					ui.explorerTree.expandPath(e.getPath());
				}				
			}});
		ExplorerTreeNode dir = (ExplorerTreeNode) e.getPath().getLastPathComponent();//tLastSelectedPathComponent();
		model.setPosition(dir.getPath() + dir.getName() + "/");
	}
}

